<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="description" content="">
  <meta name="keywords" content="">
  
    <link rel="icon" href="/avatar.jpg">
  
    
  <title>Java 8 parallelStream 在大批量小任务上的性能陷阱 | 科学君的不科学博客</title>
  <link rel="stylesheet" href="/style.css">
  <link rel="stylesheet" href="/lib/jquery.fancybox.min.css">
  <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
  <script type="text/javascript" src="https://tajs.qq.com/stats?sId=65546304" charset="UTF-8"></script>
  <script>
  (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      if (curProtocol === 'https') {
          bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
      }
      else {
          bp.src = 'http://push.zhanzhang.baidu.com/push.js';
      }
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
  })();
  </script>
</head>

<body>
  <header>
  <div class="header-container">
    <a class='logo' href="/">
      <span>科学君的不科学博客</span>
    </a>
    <ul class="right-header">
      
        <li class="nav-item">
          
            <a href="/" class="item-link">首页</a>
          
        </li>
      
        <li class="nav-item">
          
            <a href="/about" class="item-link">关于</a>
          
        </li>
      
        <li class="nav-item">
          
            <a href="/archives" class="item-link">归档</a>
          
        </li>
      
        <li class="nav-item">
          
            <a href="/tags" class="item-link">标签</a>
          
        </li>
      
        <li class="nav-item">
          
            <a href="/atom.xml" class="item-link">FEED 订阅</a>
          
        </li>
      
    </ul>
  </div>
</header>

  <main id='post'>
  <div class="content">
    <article>
      <section class="content markdown-body">
        <h1>Java 8 parallelStream 在大批量小任务上的性能陷阱</h1>
        <div class='post-meta'>
          <i class="fa fa-calendar" aria-hidden="true"></i>
          <time>2019年05月09日</time>
          
          | <i class="fa fa-folder-open-o" aria-hidden="true"></i> 
  <div class="article-category">
    <a class="article-category-link" href="/categories/blog/">blog</a>
  </div>



          
          
          |
          
          <i class="fa fa-tags" aria-hidden="true"></i>
          
          
  <a href="/tags/#java" class='tag'>java</a>

  <a href="/tags/#并发编程" class='tag'>并发编程</a>


          
        </div>
        <h1 id="tl-dr"><a href="#tl-dr" class="headerlink" title="tl;dr"></a>tl;dr</h1><p>Java 8 的 parallelStream 在运行大量的短任务（短时间执行的任务）之后会变成单线程运行，这是 parallelStream 自带的性能优化功能。但是在短任务和长任务交替执行时，这种优化会显著拖慢运行速度。</p>
<h1 id="测试代码"><a href="#测试代码" class="headerlink" title="测试代码"></a>测试代码</h1><p>我们使用下面的测试函数来进行说明。<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">(<span class="keyword">int</span> shortTaskNumber, <span class="keyword">int</span> longTaskNumber)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> ConcurrentHashMap&lt;Integer, String&gt; workingThreads = <span class="keyword">new</span> ConcurrentHashMap&lt;&gt;();</span><br><span class="line"></span><br><span class="line">    <span class="keyword">final</span> ArrayList&lt;Supplier&lt;Integer&gt;&gt; inputs = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">    <span class="comment">// 直接收集结果（大量的快速计算）</span></span><br><span class="line">    inputs.addAll(IntStream.range(<span class="number">0</span>, shortTaskNumber)</span><br><span class="line">            .boxed()</span><br><span class="line">            .map(a -&gt; (Supplier&lt;Integer&gt;) () -&gt; a)</span><br><span class="line">            .collect(Collectors.toList()));</span><br><span class="line">    <span class="comment">// 模拟长时间运算（少量的慢速计算）</span></span><br><span class="line">    inputs.addAll(IntStream.range(shortTaskNumber, shortTaskNumber + longTaskNumber)</span><br><span class="line">            .boxed()</span><br><span class="line">            .map(a -&gt; (Supplier&lt;Integer&gt;) () -&gt; &#123;</span><br><span class="line">                <span class="keyword">final</span> <span class="keyword">long</span> beg = System.currentTimeMillis();</span><br><span class="line">                <span class="keyword">final</span> <span class="keyword">long</span> end = beg + <span class="number">1000</span> * <span class="number">10</span>;</span><br><span class="line">                <span class="comment">// 模拟计算密集型操作</span></span><br><span class="line">                <span class="comment">// 其实这里换成 Thread.sleep(10000) 对结果也没影响</span></span><br><span class="line">                <span class="keyword">while</span> (System.currentTimeMillis() &lt; end) ;</span><br><span class="line">                <span class="keyword">return</span> a;</span><br><span class="line">            &#125;)</span><br><span class="line">            .collect(Collectors.toList()));</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 开始并发执行</span></span><br><span class="line">    IntStream.range(<span class="number">0</span>, inputs.size())</span><br><span class="line">            .boxed()</span><br><span class="line">            .parallel()</span><br><span class="line">            .forEach(i -&gt; &#123;</span><br><span class="line">                workingThreads.put(i, Thread.currentThread().getName());</span><br><span class="line">                <span class="comment">// 不显示不必要的信息</span></span><br><span class="line">                <span class="keyword">if</span> (i &gt;= shortTaskNumber) &#123;</span><br><span class="line">                    System.out.println(<span class="string">"On "</span> + i);</span><br><span class="line">                    System.out.println(workingThreads);</span><br><span class="line">                    System.out.println(<span class="string">"-------------------------------------"</span>);</span><br><span class="line">                &#125;</span><br><span class="line">                inputs.get(i).get();</span><br><span class="line">                workingThreads.remove(i);</span><br><span class="line">            &#125;);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>根据代码所示，我们创建了<code>shortTaskNumber</code>个立刻能得到结果的任务，和<code>longTaskNumber</code>个需要长时间计算的任务，然后把这些任务放到一个 parallelStream 中并发执行。</p>
<h1 id="少量任务的情况"><a href="#少量任务的情况" class="headerlink" title="少量任务的情况"></a>少量任务的情况</h1><p>本测试程序使用 OpenJDK 11 运行。</p>
<p>我们使用 <code>run(20, 20)</code> 来运行测试函数，得到结果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line">On 26</span><br><span class="line">&#123;26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 36</span><br><span class="line">&#123;36=ForkJoinPool.commonPool-worker-3, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 22</span><br><span class="line">&#123;36=ForkJoinPool.commonPool-worker-3, 22=ForkJoinPool.commonPool-worker-5, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 21</span><br><span class="line">On 38</span><br><span class="line">On 32</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 36=ForkJoinPool.commonPool-worker-3, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 36=ForkJoinPool.commonPool-worker-3, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 36=ForkJoinPool.commonPool-worker-3, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 35</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 36=ForkJoinPool.commonPool-worker-3, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 24</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 36=ForkJoinPool.commonPool-worker-3, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 26=main&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 28</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 21=ForkJoinPool.commonPool-worker-9, 22=ForkJoinPool.commonPool-worker-5, 38=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20</span><br><span class="line">On 25</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 21=ForkJoinPool.commonPool-worker-9, 38=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 34</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 21=ForkJoinPool.commonPool-worker-9, 38=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;32=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 21=ForkJoinPool.commonPool-worker-9, 38=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 37</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 39</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 24=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 23</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 35=ForkJoinPool.commonPool-worker-13, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 23=ForkJoinPool.commonPool-worker-15, 25=main, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 27</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 23=ForkJoinPool.commonPool-worker-15, 25=main, 27=ForkJoinPool.commonPool-worker-13, 28=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 29</span><br><span class="line">&#123;34=ForkJoinPool.commonPool-worker-11, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 23=ForkJoinPool.commonPool-worker-15, 25=main, 27=ForkJoinPool.commonPool-worker-13, 29=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 33</span><br><span class="line">&#123;33=ForkJoinPool.commonPool-worker-11, 20=ForkJoinPool.commonPool-worker-5, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 23=ForkJoinPool.commonPool-worker-15, 25=main, 27=ForkJoinPool.commonPool-worker-13, 29=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 31</span><br><span class="line">&#123;33=ForkJoinPool.commonPool-worker-11, 37=ForkJoinPool.commonPool-worker-9, 39=ForkJoinPool.commonPool-worker-7, 23=ForkJoinPool.commonPool-worker-15, 27=ForkJoinPool.commonPool-worker-13, 29=ForkJoinPool.commonPool-worker-3, 31=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 30</span><br><span class="line">&#123;33=ForkJoinPool.commonPool-worker-11, 23=ForkJoinPool.commonPool-worker-15, 27=ForkJoinPool.commonPool-worker-13, 29=ForkJoinPool.commonPool-worker-3, 30=ForkJoinPool.commonPool-worker-9, 31=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br></pre></td></tr></table></figure></p>
<p>可以看到，这些长时间的任务（index大于20的）都是并发运行的，这是我们需要的结果。</p>
<p>然而，在运行大量的任务时，情况却并不是这样。</p>
<h1 id="大量任务的情况"><a href="#大量任务的情况" class="headerlink" title="大量任务的情况"></a>大量任务的情况</h1><p>使用 <code>run(20000, 100)</code> 得到的运行结果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">On 20000</span><br><span class="line">&#123;20000=ForkJoinPool.commonPool-worker-15, 12934=main, 3081=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20001</span><br><span class="line">&#123;20001=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20002</span><br><span class="line">&#123;20002=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20003</span><br><span class="line">&#123;20003=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20004</span><br><span class="line">&#123;20004=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20005</span><br><span class="line">&#123;20005=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20006</span><br><span class="line">&#123;20006=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20007</span><br><span class="line">&#123;20007=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20008</span><br><span class="line">&#123;20008=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20009</span><br><span class="line">&#123;20009=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20010</span><br><span class="line">&#123;20010=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20011</span><br><span class="line">&#123;20011=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20012</span><br><span class="line">&#123;20012=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20013</span><br><span class="line">&#123;20013=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20014</span><br><span class="line">&#123;20014=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20015</span><br><span class="line">&#123;20015=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20016</span><br><span class="line">&#123;20016=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20017</span><br><span class="line">&#123;20017=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20018</span><br><span class="line">&#123;20018=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20019</span><br><span class="line">&#123;20019=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 20020</span><br><span class="line">&#123;20020=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line"></span><br><span class="line">（省略剩下的输出）</span><br></pre></td></tr></table></figure></p>
<p>我们在 20000 个轻计算量的任务中插入了 200 个需要长时间计算的任务，却发现这些任务并没有并行执行。我推测这是因为 parallelStream 在发现前面的任务执行速度很快之后，会推测全部的任务都是这样的短任务，并将剩下的任务放到单个线程中进行计算。</p>
<h1 id="该行为的触发时机"><a href="#该行为的触发时机" class="headerlink" title="该行为的触发时机"></a>该行为的触发时机</h1><p>为了印证这个想法，我完善了一下测试程序，得到了下面的运行结果。</p>
<p>其中四个数值（最小值，最大值，平均数，中位数）指的是“在运行某个长任务时，并发线程的数量”。</p>
<table>
<thead>
<tr>
<th>shortTaskNumber</th>
<th>longTaskNumber</th>
<th>最小值</th>
<th>最大值</th>
<th>平均数</th>
<th>中位数</th>
</tr>
</thead>
<tbody>
<tr>
<td>5</td>
<td>5</td>
<td>5</td>
<td>5</td>
<td>5.0</td>
<td>5.0</td>
</tr>
<tr>
<td>20</td>
<td>5</td>
<td>5</td>
<td>5</td>
<td>5.0</td>
<td>5.0</td>
</tr>
<tr>
<td>50</td>
<td>5</td>
<td>2</td>
<td>5</td>
<td>3.8</td>
<td>5.0</td>
</tr>
<tr>
<td>100</td>
<td>5</td>
<td>1</td>
<td>3</td>
<td>2.4</td>
<td>3.0</td>
</tr>
<tr>
<td>200</td>
<td>5</td>
<td>1</td>
<td>1</td>
<td>1.0</td>
<td>1.0</td>
</tr>
<tr>
<td>100</td>
<td>10</td>
<td>1</td>
<td>5</td>
<td>3.9</td>
<td>4.5</td>
</tr>
<tr>
<td>200</td>
<td>10</td>
<td>1</td>
<td>2</td>
<td>1.6</td>
<td>2.0</td>
</tr>
<tr>
<td>100</td>
<td>20</td>
<td>3</td>
<td>6</td>
<td>4.95</td>
<td>5.0</td>
</tr>
<tr>
<td>200</td>
<td>20</td>
<td>2</td>
<td>3</td>
<td>2.8</td>
<td>3.0</td>
</tr>
<tr>
<td>300</td>
<td>20</td>
<td>2</td>
<td>2</td>
<td>2.0</td>
<td>2.0</td>
</tr>
<tr>
<td>400</td>
<td>20</td>
<td>1</td>
<td>2</td>
<td>1.6</td>
<td>2.0</td>
</tr>
<tr>
<td>500</td>
<td>20</td>
<td>1</td>
<td>2</td>
<td>1.3</td>
<td>1.0</td>
</tr>
<tr>
<td>600</td>
<td>20</td>
<td>1</td>
<td>1</td>
<td>1.0</td>
<td>1.0</td>
</tr>
</tbody>
</table>
<p>可见，parallelStream 并不是完全按照处理器的数量来做的并行。</p>
<p>本测试的结果并不稳定，因为 parallelStream 不是按照顺序进行计算的，<br>短任务和长任务完全可能混在一起运行。同时，<code>shortTaskNumber/longTaskNumber</code> 的结果越大，parallelStream 就会使用越小的线程数来运行任务。</p>
<p>另外，我也尝试过把 parallelStream 使用的线程池更换成 FixedThreadPool，得到的结果和上面的相似，可见这也不是 ForkJoinPool 的问题。</p>
<h1 id="该特性对计算密集型任务的影响"><a href="#该特性对计算密集型任务的影响" class="headerlink" title="该特性对计算密集型任务的影响"></a>该特性对计算密集型任务的影响</h1><p>一般来说，大家都是使用 parallelStream 来进行计算密集型任务的。<br>如果拆分出来的每个任务的运行时间都差不多，那么使用 parallelStream<br>没有什么问题，一般的计算密集型任务可能都有这个特点。</p>
<p>我是在给一个科学计算项目编写代码时发现的这个问题。在那个代码中，由于每个任务的运行时间都比较长，我们会把中间结果缓存到文件中，比如下面的伪代码：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">list.parallelStream()</span><br><span class="line">.map(...)</span><br><span class="line">.map(input -&gt; &#123;</span><br><span class="line">    <span class="keyword">if</span> (isCached(input)) &#123;</span><br><span class="line">        <span class="keyword">return</span> loadCache(input);</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">        var res = resolve(input);</span><br><span class="line">        saveCache(input, res);</span><br><span class="line">        <span class="keyword">return</span> res;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;)</span><br><span class="line">.map(...)</span><br></pre></td></tr></table></figure></p>
<p>如果 list 中有几千个数据，同时其中大部分都被缓存进了文件中，则中间部分的 map 会包含大量的短任务（从文件中读取数据），而jdk的优化会让其中的长任务（直接计算）变成单线程执行。这样是非常麻烦的。</p>
<p>对于这种情况，我还没有什么比较好的解决办法。现在只能把部分受影响的代码直接改成调用 ForkJoinPool 来获取稳定的并发。</p>
<h1 id="附录：测试程序和完整的运行结果"><a href="#附录：测试程序和完整的运行结果" class="headerlink" title="附录：测试程序和完整的运行结果"></a>附录：测试程序和完整的运行结果</h1><p>测试程序：<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> java.util.ArrayList;</span><br><span class="line"><span class="keyword">import</span> java.util.Arrays;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.ConcurrentHashMap;</span><br><span class="line"><span class="keyword">import</span> java.util.concurrent.ConcurrentLinkedQueue;</span><br><span class="line"><span class="keyword">import</span> java.util.function.Supplier;</span><br><span class="line"><span class="keyword">import</span> java.util.stream.Collectors;</span><br><span class="line"><span class="keyword">import</span> java.util.stream.IntStream;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">Main</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">(String[] args)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        run(<span class="number">5</span>, <span class="number">5</span>);</span><br><span class="line">        run(<span class="number">20</span>, <span class="number">5</span>);</span><br><span class="line">        run(<span class="number">50</span>, <span class="number">5</span>);</span><br><span class="line">        run(<span class="number">100</span>, <span class="number">5</span>);</span><br><span class="line">        run(<span class="number">200</span>, <span class="number">5</span>);</span><br><span class="line"></span><br><span class="line">        run(<span class="number">100</span>, <span class="number">10</span>);</span><br><span class="line">        run(<span class="number">200</span>, <span class="number">10</span>);</span><br><span class="line"></span><br><span class="line">        run(<span class="number">100</span>, <span class="number">20</span>);</span><br><span class="line">        run(<span class="number">200</span>, <span class="number">20</span>);</span><br><span class="line">        run(<span class="number">300</span>, <span class="number">20</span>);</span><br><span class="line">        run(<span class="number">400</span>, <span class="number">20</span>);</span><br><span class="line">        run(<span class="number">500</span>, <span class="number">20</span>);</span><br><span class="line">        run(<span class="number">600</span>, <span class="number">20</span>);</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">run</span><span class="params">(<span class="keyword">int</span> shortTaskNumber, <span class="keyword">int</span> longTaskNumber)</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">        System.out.println();</span><br><span class="line">        System.out.println(<span class="string">"shortTaskNumber: "</span> + shortTaskNumber + <span class="string">", longTaskNumber: "</span> + longTaskNumber);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> ConcurrentHashMap&lt;Integer, String&gt; workingThreads = <span class="keyword">new</span> ConcurrentHashMap&lt;&gt;();</span><br><span class="line">        <span class="keyword">final</span> ConcurrentLinkedQueue&lt;Integer&gt; parallelThreadNumber = <span class="keyword">new</span> ConcurrentLinkedQueue&lt;&gt;();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> ArrayList&lt;Supplier&lt;Integer&gt;&gt; inputs = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">        <span class="comment">// 直接收集结果（大量的快速获得的数据）</span></span><br><span class="line">        inputs.addAll(IntStream.range(<span class="number">0</span>, shortTaskNumber)</span><br><span class="line">                .boxed()</span><br><span class="line">                .map(a -&gt; (Supplier&lt;Integer&gt;) () -&gt; a)</span><br><span class="line">                .collect(Collectors.toList()));</span><br><span class="line">        <span class="comment">// 模拟长时间运算（少量的慢速计算的数据）</span></span><br><span class="line">        inputs.addAll(IntStream.range(shortTaskNumber, shortTaskNumber + longTaskNumber)</span><br><span class="line">                .boxed()</span><br><span class="line">                .map(a -&gt; (Supplier&lt;Integer&gt;) () -&gt; &#123;</span><br><span class="line">                    <span class="keyword">final</span> <span class="keyword">long</span> beg = System.currentTimeMillis();</span><br><span class="line">                    <span class="keyword">final</span> <span class="keyword">long</span> end = beg + <span class="number">1000</span> * <span class="number">10</span>;</span><br><span class="line">                    <span class="comment">// 模拟计算密集型操作</span></span><br><span class="line">                    <span class="comment">// 其实这里换成 Thread.sleep(10000) 对结果也没影响</span></span><br><span class="line">                    <span class="keyword">while</span> (System.currentTimeMillis() &lt; end) ;</span><br><span class="line">                    <span class="keyword">return</span> a;</span><br><span class="line">                &#125;)</span><br><span class="line">                .collect(Collectors.toList()));</span><br><span class="line"></span><br><span class="line">        IntStream.range(<span class="number">0</span>, inputs.size())</span><br><span class="line">                .boxed()</span><br><span class="line">                .parallel()</span><br><span class="line">                .forEach(i -&gt; &#123;</span><br><span class="line">                    workingThreads.put(i, Thread.currentThread().getName());</span><br><span class="line">                    inputs.get(i).get();</span><br><span class="line">                    <span class="keyword">if</span> (i &gt;= shortTaskNumber) &#123;</span><br><span class="line">                        <span class="comment">// 固定一下当前状态下的线程，防止统计的数量和输出的日志不一致</span></span><br><span class="line">                        <span class="keyword">final</span> String output = workingThreads.toString();</span><br><span class="line">                        <span class="comment">// 字符串中等号的数量就是当前的并发线程数</span></span><br><span class="line">                        parallelThreadNumber.add((<span class="keyword">int</span>) output.chars().filter(c -&gt; c == <span class="string">'='</span>).count());</span><br><span class="line">                        System.out.println(<span class="string">"On "</span> + i);</span><br><span class="line">                        System.out.println(workingThreads);</span><br><span class="line">                        System.out.println(<span class="string">"-------------------------------------"</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                    workingThreads.remove(i);</span><br><span class="line">                &#125;);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">int</span>[] ints = parallelThreadNumber</span><br><span class="line">                .stream()</span><br><span class="line">                .mapToInt(a -&gt; a)</span><br><span class="line">                .toArray();</span><br><span class="line">        Arrays.sort(ints);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">int</span> min = ints[<span class="number">0</span>];</span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">int</span> max = ints[ints.length - <span class="number">1</span>];</span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">double</span> average = Arrays.stream(ints).average().getAsDouble();</span><br><span class="line">        <span class="keyword">final</span> <span class="keyword">double</span> middle;</span><br><span class="line">        <span class="keyword">if</span> (ints.length % <span class="number">2</span> == <span class="number">0</span>) &#123;</span><br><span class="line">            <span class="keyword">final</span> <span class="keyword">int</span> i = ints.length / <span class="number">2</span>;</span><br><span class="line">            middle = (ints[i - <span class="number">1</span>] + ints[i + <span class="number">1</span>]) / <span class="number">2.0</span>;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            middle = ints[ints.length / <span class="number">2</span>];</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        System.out.println(<span class="string">"长任务中的并发线程数： Min: "</span> + min + <span class="string">", Max: "</span> + max + <span class="string">", 平均数: "</span> + average + <span class="string">", 中位数: "</span> + middle);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>完整运行结果：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br><span class="line">166</span><br><span class="line">167</span><br><span class="line">168</span><br><span class="line">169</span><br><span class="line">170</span><br><span class="line">171</span><br><span class="line">172</span><br><span class="line">173</span><br><span class="line">174</span><br><span class="line">175</span><br><span class="line">176</span><br><span class="line">177</span><br><span class="line">178</span><br><span class="line">179</span><br><span class="line">180</span><br><span class="line">181</span><br><span class="line">182</span><br><span class="line">183</span><br><span class="line">184</span><br><span class="line">185</span><br><span class="line">186</span><br><span class="line">187</span><br><span class="line">188</span><br><span class="line">189</span><br><span class="line">190</span><br><span class="line">191</span><br><span class="line">192</span><br><span class="line">193</span><br><span class="line">194</span><br><span class="line">195</span><br><span class="line">196</span><br><span class="line">197</span><br><span class="line">198</span><br><span class="line">199</span><br><span class="line">200</span><br><span class="line">201</span><br><span class="line">202</span><br><span class="line">203</span><br><span class="line">204</span><br><span class="line">205</span><br><span class="line">206</span><br><span class="line">207</span><br><span class="line">208</span><br><span class="line">209</span><br><span class="line">210</span><br><span class="line">211</span><br><span class="line">212</span><br><span class="line">213</span><br><span class="line">214</span><br><span class="line">215</span><br><span class="line">216</span><br><span class="line">217</span><br><span class="line">218</span><br><span class="line">219</span><br><span class="line">220</span><br><span class="line">221</span><br><span class="line">222</span><br><span class="line">223</span><br><span class="line">224</span><br><span class="line">225</span><br><span class="line">226</span><br><span class="line">227</span><br><span class="line">228</span><br><span class="line">229</span><br><span class="line">230</span><br><span class="line">231</span><br><span class="line">232</span><br><span class="line">233</span><br><span class="line">234</span><br><span class="line">235</span><br><span class="line">236</span><br><span class="line">237</span><br><span class="line">238</span><br><span class="line">239</span><br><span class="line">240</span><br><span class="line">241</span><br><span class="line">242</span><br><span class="line">243</span><br><span class="line">244</span><br><span class="line">245</span><br><span class="line">246</span><br><span class="line">247</span><br><span class="line">248</span><br><span class="line">249</span><br><span class="line">250</span><br><span class="line">251</span><br><span class="line">252</span><br><span class="line">253</span><br><span class="line">254</span><br><span class="line">255</span><br><span class="line">256</span><br><span class="line">257</span><br><span class="line">258</span><br><span class="line">259</span><br><span class="line">260</span><br><span class="line">261</span><br><span class="line">262</span><br><span class="line">263</span><br><span class="line">264</span><br><span class="line">265</span><br><span class="line">266</span><br><span class="line">267</span><br><span class="line">268</span><br><span class="line">269</span><br><span class="line">270</span><br><span class="line">271</span><br><span class="line">272</span><br><span class="line">273</span><br><span class="line">274</span><br><span class="line">275</span><br><span class="line">276</span><br><span class="line">277</span><br><span class="line">278</span><br><span class="line">279</span><br><span class="line">280</span><br><span class="line">281</span><br><span class="line">282</span><br><span class="line">283</span><br><span class="line">284</span><br><span class="line">285</span><br><span class="line">286</span><br><span class="line">287</span><br><span class="line">288</span><br><span class="line">289</span><br><span class="line">290</span><br><span class="line">291</span><br><span class="line">292</span><br><span class="line">293</span><br><span class="line">294</span><br><span class="line">295</span><br><span class="line">296</span><br><span class="line">297</span><br><span class="line">298</span><br><span class="line">299</span><br><span class="line">300</span><br><span class="line">301</span><br><span class="line">302</span><br><span class="line">303</span><br><span class="line">304</span><br><span class="line">305</span><br><span class="line">306</span><br><span class="line">307</span><br><span class="line">308</span><br><span class="line">309</span><br><span class="line">310</span><br><span class="line">311</span><br><span class="line">312</span><br><span class="line">313</span><br><span class="line">314</span><br><span class="line">315</span><br><span class="line">316</span><br><span class="line">317</span><br><span class="line">318</span><br><span class="line">319</span><br><span class="line">320</span><br><span class="line">321</span><br><span class="line">322</span><br><span class="line">323</span><br><span class="line">324</span><br><span class="line">325</span><br><span class="line">326</span><br><span class="line">327</span><br><span class="line">328</span><br><span class="line">329</span><br><span class="line">330</span><br><span class="line">331</span><br><span class="line">332</span><br><span class="line">333</span><br><span class="line">334</span><br><span class="line">335</span><br><span class="line">336</span><br><span class="line">337</span><br><span class="line">338</span><br><span class="line">339</span><br><span class="line">340</span><br><span class="line">341</span><br><span class="line">342</span><br><span class="line">343</span><br><span class="line">344</span><br><span class="line">345</span><br><span class="line">346</span><br><span class="line">347</span><br><span class="line">348</span><br><span class="line">349</span><br><span class="line">350</span><br><span class="line">351</span><br><span class="line">352</span><br><span class="line">353</span><br><span class="line">354</span><br><span class="line">355</span><br><span class="line">356</span><br><span class="line">357</span><br><span class="line">358</span><br><span class="line">359</span><br><span class="line">360</span><br><span class="line">361</span><br><span class="line">362</span><br><span class="line">363</span><br><span class="line">364</span><br><span class="line">365</span><br><span class="line">366</span><br><span class="line">367</span><br><span class="line">368</span><br><span class="line">369</span><br><span class="line">370</span><br><span class="line">371</span><br><span class="line">372</span><br><span class="line">373</span><br><span class="line">374</span><br><span class="line">375</span><br><span class="line">376</span><br><span class="line">377</span><br><span class="line">378</span><br><span class="line">379</span><br><span class="line">380</span><br><span class="line">381</span><br><span class="line">382</span><br><span class="line">383</span><br><span class="line">384</span><br><span class="line">385</span><br><span class="line">386</span><br><span class="line">387</span><br><span class="line">388</span><br><span class="line">389</span><br><span class="line">390</span><br><span class="line">391</span><br><span class="line">392</span><br><span class="line">393</span><br><span class="line">394</span><br><span class="line">395</span><br><span class="line">396</span><br><span class="line">397</span><br><span class="line">398</span><br><span class="line">399</span><br><span class="line">400</span><br><span class="line">401</span><br><span class="line">402</span><br><span class="line">403</span><br><span class="line">404</span><br><span class="line">405</span><br><span class="line">406</span><br><span class="line">407</span><br><span class="line">408</span><br><span class="line">409</span><br><span class="line">410</span><br><span class="line">411</span><br><span class="line">412</span><br><span class="line">413</span><br><span class="line">414</span><br><span class="line">415</span><br><span class="line">416</span><br><span class="line">417</span><br><span class="line">418</span><br><span class="line">419</span><br><span class="line">420</span><br><span class="line">421</span><br><span class="line">422</span><br><span class="line">423</span><br><span class="line">424</span><br><span class="line">425</span><br><span class="line">426</span><br><span class="line">427</span><br><span class="line">428</span><br><span class="line">429</span><br><span class="line">430</span><br><span class="line">431</span><br><span class="line">432</span><br><span class="line">433</span><br><span class="line">434</span><br><span class="line">435</span><br><span class="line">436</span><br><span class="line">437</span><br><span class="line">438</span><br><span class="line">439</span><br><span class="line">440</span><br><span class="line">441</span><br><span class="line">442</span><br><span class="line">443</span><br><span class="line">444</span><br><span class="line">445</span><br><span class="line">446</span><br><span class="line">447</span><br><span class="line">448</span><br><span class="line">449</span><br><span class="line">450</span><br><span class="line">451</span><br><span class="line">452</span><br><span class="line">453</span><br><span class="line">454</span><br><span class="line">455</span><br><span class="line">456</span><br><span class="line">457</span><br><span class="line">458</span><br><span class="line">459</span><br><span class="line">460</span><br><span class="line">461</span><br><span class="line">462</span><br><span class="line">463</span><br><span class="line">464</span><br><span class="line">465</span><br><span class="line">466</span><br><span class="line">467</span><br><span class="line">468</span><br><span class="line">469</span><br><span class="line">470</span><br><span class="line">471</span><br><span class="line">472</span><br><span class="line">473</span><br><span class="line">474</span><br><span class="line">475</span><br><span class="line">476</span><br><span class="line">477</span><br><span class="line">478</span><br><span class="line">479</span><br><span class="line">480</span><br><span class="line">481</span><br><span class="line">482</span><br><span class="line">483</span><br><span class="line">484</span><br><span class="line">485</span><br><span class="line">486</span><br><span class="line">487</span><br><span class="line">488</span><br><span class="line">489</span><br><span class="line">490</span><br><span class="line">491</span><br><span class="line">492</span><br><span class="line">493</span><br><span class="line">494</span><br><span class="line">495</span><br><span class="line">496</span><br><span class="line">497</span><br><span class="line">498</span><br><span class="line">499</span><br><span class="line">500</span><br><span class="line">501</span><br><span class="line">502</span><br><span class="line">503</span><br><span class="line">504</span><br><span class="line">505</span><br><span class="line">506</span><br><span class="line">507</span><br><span class="line">508</span><br><span class="line">509</span><br><span class="line">510</span><br><span class="line">511</span><br><span class="line">512</span><br><span class="line">513</span><br><span class="line">514</span><br><span class="line">515</span><br><span class="line">516</span><br><span class="line">517</span><br><span class="line">518</span><br><span class="line">519</span><br><span class="line">520</span><br><span class="line">521</span><br><span class="line">522</span><br><span class="line">523</span><br><span class="line">524</span><br><span class="line">525</span><br><span class="line">526</span><br><span class="line">527</span><br><span class="line">528</span><br><span class="line">529</span><br><span class="line">530</span><br><span class="line">531</span><br><span class="line">532</span><br><span class="line">533</span><br></pre></td><td class="code"><pre><span class="line">shortTaskNumber: 5, longTaskNumber: 5</span><br><span class="line">On 7</span><br><span class="line">On 8</span><br><span class="line">On 5</span><br><span class="line">On 6</span><br><span class="line">&#123;5=ForkJoinPool.commonPool-worker-9, 6=main, 7=ForkJoinPool.commonPool-worker-3, 8=ForkJoinPool.commonPool-worker-5, 9=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;5=ForkJoinPool.commonPool-worker-9, 6=main, 7=ForkJoinPool.commonPool-worker-3, 8=ForkJoinPool.commonPool-worker-5, 9=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;5=ForkJoinPool.commonPool-worker-9, 6=main, 7=ForkJoinPool.commonPool-worker-3, 8=ForkJoinPool.commonPool-worker-5, 9=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 9</span><br><span class="line">&#123;5=ForkJoinPool.commonPool-worker-9, 6=main, 7=ForkJoinPool.commonPool-worker-3, 8=ForkJoinPool.commonPool-worker-5, 9=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;6=main, 9=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 5, Max: 5, 平均数: 5.0, 中位数: 5.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 20, longTaskNumber: 5</span><br><span class="line">On 24</span><br><span class="line">On 23</span><br><span class="line">On 20</span><br><span class="line">On 21</span><br><span class="line">On 22</span><br><span class="line">&#123;20=ForkJoinPool.commonPool-worker-7, 21=ForkJoinPool.commonPool-worker-5, 22=ForkJoinPool.commonPool-worker-3, 23=ForkJoinPool.commonPool-worker-15, 24=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;20=ForkJoinPool.commonPool-worker-7, 21=ForkJoinPool.commonPool-worker-5, 22=ForkJoinPool.commonPool-worker-3, 23=ForkJoinPool.commonPool-worker-15, 24=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;20=ForkJoinPool.commonPool-worker-7, 21=ForkJoinPool.commonPool-worker-5, 22=ForkJoinPool.commonPool-worker-3, 23=ForkJoinPool.commonPool-worker-15, 24=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;20=ForkJoinPool.commonPool-worker-7, 21=ForkJoinPool.commonPool-worker-5, 22=ForkJoinPool.commonPool-worker-3, 23=ForkJoinPool.commonPool-worker-15, 24=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;20=ForkJoinPool.commonPool-worker-7, 21=ForkJoinPool.commonPool-worker-5, 22=ForkJoinPool.commonPool-worker-3, 23=ForkJoinPool.commonPool-worker-15, 24=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 5, Max: 5, 平均数: 5.0, 中位数: 5.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 50, longTaskNumber: 5</span><br><span class="line">On 52</span><br><span class="line">On 53</span><br><span class="line">On 50</span><br><span class="line">&#123;50=ForkJoinPool.commonPool-worker-9, 51=ForkJoinPool.commonPool-worker-15, 52=ForkJoinPool.commonPool-worker-13, 53=ForkJoinPool.commonPool-worker-11, 54=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;50=ForkJoinPool.commonPool-worker-9, 51=ForkJoinPool.commonPool-worker-15, 52=ForkJoinPool.commonPool-worker-13, 53=ForkJoinPool.commonPool-worker-11, 54=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;50=ForkJoinPool.commonPool-worker-9, 51=ForkJoinPool.commonPool-worker-15, 52=ForkJoinPool.commonPool-worker-13, 53=ForkJoinPool.commonPool-worker-11, 54=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 51</span><br><span class="line">&#123;51=ForkJoinPool.commonPool-worker-15, 54=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 54</span><br><span class="line">&#123;54=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 2, Max: 5, 平均数: 3.8, 中位数: 5.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 100, longTaskNumber: 5</span><br><span class="line">On 101</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-5, 101=ForkJoinPool.commonPool-worker-11, 103=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 100</span><br><span class="line">On 103</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-5, 102=ForkJoinPool.commonPool-worker-11, 103=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-5, 102=ForkJoinPool.commonPool-worker-11, 103=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 102</span><br><span class="line">&#123;102=ForkJoinPool.commonPool-worker-11, 104=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 104</span><br><span class="line">&#123;104=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 3, 平均数: 2.4, 中位数: 3.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 200, longTaskNumber: 5</span><br><span class="line">On 200</span><br><span class="line">&#123;200=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 201</span><br><span class="line">&#123;201=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 202</span><br><span class="line">&#123;202=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 203</span><br><span class="line">&#123;203=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 204</span><br><span class="line">&#123;204=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 1, 平均数: 1.0, 中位数: 1.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 100, longTaskNumber: 10</span><br><span class="line">On 103</span><br><span class="line">On 101</span><br><span class="line">On 106</span><br><span class="line">On 100</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-5, 103=ForkJoinPool.commonPool-worker-9, 106=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-5, 103=ForkJoinPool.commonPool-worker-9, 106=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-5, 103=ForkJoinPool.commonPool-worker-9, 106=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;100=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-5, 103=ForkJoinPool.commonPool-worker-9, 106=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 108</span><br><span class="line">&#123;102=ForkJoinPool.commonPool-worker-5, 104=ForkJoinPool.commonPool-worker-9, 107=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 107</span><br><span class="line">On 104</span><br><span class="line">On 102</span><br><span class="line">&#123;102=ForkJoinPool.commonPool-worker-5, 104=ForkJoinPool.commonPool-worker-9, 107=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;102=ForkJoinPool.commonPool-worker-5, 104=ForkJoinPool.commonPool-worker-9, 107=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">&#123;102=ForkJoinPool.commonPool-worker-5, 104=ForkJoinPool.commonPool-worker-9, 107=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">-------------------------------------</span><br><span class="line">On 109</span><br><span class="line">&#123;105=ForkJoinPool.commonPool-worker-9, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 105</span><br><span class="line">&#123;105=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 5, 平均数: 3.9, 中位数: 4.5</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 200, longTaskNumber: 10</span><br><span class="line">On 203</span><br><span class="line">&#123;200=ForkJoinPool.commonPool-worker-13, 203=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 200</span><br><span class="line">&#123;200=ForkJoinPool.commonPool-worker-13, 204=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 204</span><br><span class="line">&#123;201=ForkJoinPool.commonPool-worker-13, 204=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 201</span><br><span class="line">&#123;201=ForkJoinPool.commonPool-worker-13, 205=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 205</span><br><span class="line">&#123;202=ForkJoinPool.commonPool-worker-13, 205=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 202</span><br><span class="line">&#123;202=ForkJoinPool.commonPool-worker-13, 206=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 206</span><br><span class="line">&#123;206=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 207</span><br><span class="line">&#123;207=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 208</span><br><span class="line">&#123;208=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 209</span><br><span class="line">&#123;209=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 2, 平均数: 1.6, 中位数: 2.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 100, longTaskNumber: 20</span><br><span class="line">On 108</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 108=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 112</span><br><span class="line">On 100</span><br><span class="line">On 105</span><br><span class="line">On 101</span><br><span class="line">On 116</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;112=ForkJoinPool.commonPool-worker-5, 100=ForkJoinPool.commonPool-worker-9, 116=ForkJoinPool.commonPool-worker-7, 101=ForkJoinPool.commonPool-worker-15, 105=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 109</span><br><span class="line">&#123;113=ForkJoinPool.commonPool-worker-5, 117=ForkJoinPool.commonPool-worker-7, 102=ForkJoinPool.commonPool-worker-15, 106=ForkJoinPool.commonPool-worker-13, 109=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 106</span><br><span class="line">&#123;113=ForkJoinPool.commonPool-worker-5, 117=ForkJoinPool.commonPool-worker-7, 102=ForkJoinPool.commonPool-worker-15, 106=ForkJoinPool.commonPool-worker-13, 110=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 117</span><br><span class="line">&#123;113=ForkJoinPool.commonPool-worker-5, 117=ForkJoinPool.commonPool-worker-7, 102=ForkJoinPool.commonPool-worker-15, 107=ForkJoinPool.commonPool-worker-13, 110=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 102</span><br><span class="line">On 113</span><br><span class="line">&#123;113=ForkJoinPool.commonPool-worker-5, 102=ForkJoinPool.commonPool-worker-15, 118=ForkJoinPool.commonPool-worker-7, 107=ForkJoinPool.commonPool-worker-13, 110=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;113=ForkJoinPool.commonPool-worker-5, 102=ForkJoinPool.commonPool-worker-15, 118=ForkJoinPool.commonPool-worker-7, 107=ForkJoinPool.commonPool-worker-13, 110=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 110</span><br><span class="line">&#123;114=ForkJoinPool.commonPool-worker-5, 118=ForkJoinPool.commonPool-worker-7, 103=ForkJoinPool.commonPool-worker-15, 107=ForkJoinPool.commonPool-worker-13, 110=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 103</span><br><span class="line">&#123;114=ForkJoinPool.commonPool-worker-5, 118=ForkJoinPool.commonPool-worker-7, 103=ForkJoinPool.commonPool-worker-15, 107=ForkJoinPool.commonPool-worker-13, 111=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 114</span><br><span class="line">On 107</span><br><span class="line">&#123;114=ForkJoinPool.commonPool-worker-5, 118=ForkJoinPool.commonPool-worker-7, 104=ForkJoinPool.commonPool-worker-15, 107=ForkJoinPool.commonPool-worker-13, 111=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 118</span><br><span class="line">&#123;114=ForkJoinPool.commonPool-worker-5, 118=ForkJoinPool.commonPool-worker-7, 104=ForkJoinPool.commonPool-worker-15, 107=ForkJoinPool.commonPool-worker-13, 111=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;114=ForkJoinPool.commonPool-worker-5, 118=ForkJoinPool.commonPool-worker-7, 104=ForkJoinPool.commonPool-worker-15, 111=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 111</span><br><span class="line">&#123;115=ForkJoinPool.commonPool-worker-5, 119=ForkJoinPool.commonPool-worker-7, 104=ForkJoinPool.commonPool-worker-15, 111=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 119</span><br><span class="line">&#123;115=ForkJoinPool.commonPool-worker-5, 119=ForkJoinPool.commonPool-worker-7, 104=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 115</span><br><span class="line">&#123;115=ForkJoinPool.commonPool-worker-5, 104=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 104</span><br><span class="line">&#123;104=ForkJoinPool.commonPool-worker-15&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 3, Max: 6, 平均数: 4.95, 中位数: 5.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 200, longTaskNumber: 20</span><br><span class="line">On 200</span><br><span class="line">&#123;213=ForkJoinPool.commonPool-worker-11, 200=ForkJoinPool.commonPool-worker-5, 206=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 213</span><br><span class="line">&#123;213=ForkJoinPool.commonPool-worker-11, 201=ForkJoinPool.commonPool-worker-5, 206=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 206</span><br><span class="line">&#123;214=ForkJoinPool.commonPool-worker-11, 201=ForkJoinPool.commonPool-worker-5, 206=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 201</span><br><span class="line">&#123;214=ForkJoinPool.commonPool-worker-11, 201=ForkJoinPool.commonPool-worker-5, 207=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 214</span><br><span class="line">On 207</span><br><span class="line">&#123;214=ForkJoinPool.commonPool-worker-11, 202=ForkJoinPool.commonPool-worker-5, 207=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">&#123;214=ForkJoinPool.commonPool-worker-11, 202=ForkJoinPool.commonPool-worker-5, 207=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 202</span><br><span class="line">&#123;208=ForkJoinPool.commonPool-worker-13, 215=ForkJoinPool.commonPool-worker-11, 202=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 215</span><br><span class="line">&#123;208=ForkJoinPool.commonPool-worker-13, 215=ForkJoinPool.commonPool-worker-11, 203=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 208</span><br><span class="line">&#123;208=ForkJoinPool.commonPool-worker-13, 216=ForkJoinPool.commonPool-worker-11, 203=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 203</span><br><span class="line">&#123;209=ForkJoinPool.commonPool-worker-13, 216=ForkJoinPool.commonPool-worker-11, 203=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 209</span><br><span class="line">&#123;209=ForkJoinPool.commonPool-worker-13, 216=ForkJoinPool.commonPool-worker-11, 204=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 216</span><br><span class="line">&#123;210=ForkJoinPool.commonPool-worker-13, 216=ForkJoinPool.commonPool-worker-11, 204=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 204</span><br><span class="line">&#123;210=ForkJoinPool.commonPool-worker-13, 217=ForkJoinPool.commonPool-worker-11, 204=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 210</span><br><span class="line">&#123;210=ForkJoinPool.commonPool-worker-13, 217=ForkJoinPool.commonPool-worker-11, 205=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 217</span><br><span class="line">&#123;211=ForkJoinPool.commonPool-worker-13, 217=ForkJoinPool.commonPool-worker-11, 205=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 205</span><br><span class="line">&#123;211=ForkJoinPool.commonPool-worker-13, 218=ForkJoinPool.commonPool-worker-11, 205=ForkJoinPool.commonPool-worker-5&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 211</span><br><span class="line">&#123;211=ForkJoinPool.commonPool-worker-13, 218=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 218</span><br><span class="line">&#123;212=ForkJoinPool.commonPool-worker-13, 218=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 219</span><br><span class="line">&#123;212=ForkJoinPool.commonPool-worker-13, 219=ForkJoinPool.commonPool-worker-11&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 212</span><br><span class="line">&#123;212=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 2, Max: 3, 平均数: 2.8, 中位数: 3.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 300, longTaskNumber: 20</span><br><span class="line">On 310</span><br><span class="line">&#123;310=ForkJoinPool.commonPool-worker-7, 300=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 300</span><br><span class="line">&#123;311=ForkJoinPool.commonPool-worker-7, 300=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 311</span><br><span class="line">&#123;311=ForkJoinPool.commonPool-worker-7, 301=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">On 301</span><br><span class="line">&#123;311=ForkJoinPool.commonPool-worker-7, 301=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">-------------------------------------</span><br><span class="line">On 312</span><br><span class="line">&#123;312=ForkJoinPool.commonPool-worker-7, 302=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 302</span><br><span class="line">&#123;313=ForkJoinPool.commonPool-worker-7, 302=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 313</span><br><span class="line">&#123;313=ForkJoinPool.commonPool-worker-7, 303=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 303</span><br><span class="line">&#123;314=ForkJoinPool.commonPool-worker-7, 303=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 314</span><br><span class="line">&#123;304=ForkJoinPool.commonPool-worker-9, 314=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 304</span><br><span class="line">&#123;304=ForkJoinPool.commonPool-worker-9, 315=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 315</span><br><span class="line">&#123;305=ForkJoinPool.commonPool-worker-9, 315=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 305</span><br><span class="line">&#123;305=ForkJoinPool.commonPool-worker-9, 316=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 306</span><br><span class="line">&#123;306=ForkJoinPool.commonPool-worker-9, 316=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 316</span><br><span class="line">&#123;307=ForkJoinPool.commonPool-worker-9, 316=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 317</span><br><span class="line">&#123;307=ForkJoinPool.commonPool-worker-9, 317=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 307</span><br><span class="line">&#123;307=ForkJoinPool.commonPool-worker-9, 318=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 318</span><br><span class="line">&#123;308=ForkJoinPool.commonPool-worker-9, 318=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 308</span><br><span class="line">&#123;308=ForkJoinPool.commonPool-worker-9, 319=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 319</span><br><span class="line">&#123;309=ForkJoinPool.commonPool-worker-9, 319=ForkJoinPool.commonPool-worker-7&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 309</span><br><span class="line">&#123;309=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 2, Max: 2, 平均数: 2.0, 中位数: 2.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 400, longTaskNumber: 20</span><br><span class="line">On 406</span><br><span class="line">&#123;400=ForkJoinPool.commonPool-worker-9, 406=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 400</span><br><span class="line">&#123;400=ForkJoinPool.commonPool-worker-9, 407=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 407</span><br><span class="line">&#123;401=ForkJoinPool.commonPool-worker-9, 407=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 401</span><br><span class="line">&#123;401=ForkJoinPool.commonPool-worker-9, 408=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 408</span><br><span class="line">&#123;402=ForkJoinPool.commonPool-worker-9, 408=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 402</span><br><span class="line">&#123;402=ForkJoinPool.commonPool-worker-9, 409=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 409</span><br><span class="line">&#123;403=ForkJoinPool.commonPool-worker-9, 409=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 403</span><br><span class="line">&#123;403=ForkJoinPool.commonPool-worker-9, 410=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 410</span><br><span class="line">&#123;404=ForkJoinPool.commonPool-worker-9, 410=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 404</span><br><span class="line">&#123;404=ForkJoinPool.commonPool-worker-9, 411=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 411</span><br><span class="line">&#123;405=ForkJoinPool.commonPool-worker-9, 411=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 405</span><br><span class="line">&#123;405=ForkJoinPool.commonPool-worker-9, 412=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 412</span><br><span class="line">&#123;412=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 413</span><br><span class="line">&#123;413=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 414</span><br><span class="line">&#123;414=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 415</span><br><span class="line">&#123;415=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 416</span><br><span class="line">&#123;416=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 417</span><br><span class="line">&#123;417=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 418</span><br><span class="line">&#123;418=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 419</span><br><span class="line">&#123;419=ForkJoinPool.commonPool-worker-13&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 2, 平均数: 1.6, 中位数: 2.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 500, longTaskNumber: 20</span><br><span class="line">On 503</span><br><span class="line">&#123;500=ForkJoinPool.commonPool-worker-3, 503=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 500</span><br><span class="line">&#123;500=ForkJoinPool.commonPool-worker-3, 504=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 504</span><br><span class="line">&#123;501=ForkJoinPool.commonPool-worker-3, 504=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 501</span><br><span class="line">&#123;501=ForkJoinPool.commonPool-worker-3, 505=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 505</span><br><span class="line">&#123;502=ForkJoinPool.commonPool-worker-3, 505=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 502</span><br><span class="line">&#123;502=ForkJoinPool.commonPool-worker-3, 506=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 506</span><br><span class="line">&#123;506=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 507</span><br><span class="line">&#123;507=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 508</span><br><span class="line">&#123;508=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 509</span><br><span class="line">&#123;509=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 510</span><br><span class="line">&#123;510=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 511</span><br><span class="line">&#123;511=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 512</span><br><span class="line">&#123;512=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 513</span><br><span class="line">&#123;513=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 514</span><br><span class="line">&#123;514=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 515</span><br><span class="line">&#123;515=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 516</span><br><span class="line">&#123;516=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 517</span><br><span class="line">&#123;517=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 518</span><br><span class="line">&#123;518=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 519</span><br><span class="line">&#123;519=ForkJoinPool.commonPool-worker-9&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 2, 平均数: 1.3, 中位数: 1.0</span><br><span class="line"></span><br><span class="line">shortTaskNumber: 600, longTaskNumber: 20</span><br><span class="line">On 600</span><br><span class="line">&#123;600=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 601</span><br><span class="line">&#123;601=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 602</span><br><span class="line">&#123;602=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 603</span><br><span class="line">&#123;603=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 604</span><br><span class="line">&#123;604=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 605</span><br><span class="line">&#123;605=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 606</span><br><span class="line">&#123;606=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 607</span><br><span class="line">&#123;607=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 608</span><br><span class="line">&#123;608=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 609</span><br><span class="line">&#123;609=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 610</span><br><span class="line">&#123;610=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 611</span><br><span class="line">&#123;611=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 612</span><br><span class="line">&#123;612=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 613</span><br><span class="line">&#123;613=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 614</span><br><span class="line">&#123;614=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 615</span><br><span class="line">&#123;615=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 616</span><br><span class="line">&#123;616=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 617</span><br><span class="line">&#123;617=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 618</span><br><span class="line">&#123;618=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">On 619</span><br><span class="line">&#123;619=ForkJoinPool.commonPool-worker-3&#125;</span><br><span class="line">-------------------------------------</span><br><span class="line">长任务中的并发线程数： Min: 1, Max: 1, 平均数: 1.0, 中位数: 1.0</span><br></pre></td></tr></table></figure></p>

      </section>
      <div class="license">
        <a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license" target="_blank">
          <img src="http://i.creativecommons.org/l/by-sa/3.0/88x31.png" style="border-width:0"
               alt="Creative Commons License" class="center">
        </a>
      </div>
      <p>
        本作品采用
        <a rel="license" href="https://creativecommons.org/licenses/by-sa/4.0/deed.zh" target="_blank">
          署名-相同方式共享 4.0 国际
        </a>
        进行许可。欢迎转载、使用、重新发布，但务必保留文章署名
        “不科学的科学君” (Liu233w) 与博客链接：
        <a href="https://liu233w.github.io">https://liu233w.github.io</a>
        ，基于本文修改后的作品务必以相同的许可发布。如有任何疑问，请
        <a href="mailto:wwwlsmcom@outlook.com" target="_blank">与我联系</a>
        。
      </p>
    </article>
    
    <!-- disqus 评论框 start -->
    <div class="comment">
      <div id="disqus_thread" class="disqus-thread">
        <i>加载评论框需要翻墙</i>
      </div>
    </div>
    <!-- disqus 评论框 end -->
    
    
    <!-- livere 评论框 start -->
    <div class="comment">
      <div id="lv-container" data-id="city" data-uid="MTAyMC8zNTE5NS8xMTczMA=="></div>
    </div>
    <!-- livere 评论框 end -->
    
  </div>
  <aside>
    
    <div class="toc-container">
      <h1>目录</h1>
      <div class="content">
        <ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#tl-dr"><span class="toc-number">1.</span> <span class="toc-text">tl;dr</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#测试代码"><span class="toc-number">2.</span> <span class="toc-text">测试代码</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#少量任务的情况"><span class="toc-number">3.</span> <span class="toc-text">少量任务的情况</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#大量任务的情况"><span class="toc-number">4.</span> <span class="toc-text">大量任务的情况</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#该行为的触发时机"><span class="toc-number">5.</span> <span class="toc-text">该行为的触发时机</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#该特性对计算密集型任务的影响"><span class="toc-number">6.</span> <span class="toc-text">该特性对计算密集型任务的影响</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#附录：测试程序和完整的运行结果"><span class="toc-number">7.</span> <span class="toc-text">附录：测试程序和完整的运行结果</span></a></li></ol>
      </div>
    </div>
    
  </aside>
</main>

<!-- disqus 公共JS代码 -->
<script type="text/javascript">
  /* * * CONFIGURATION VARIABLES * * */
  var disqus_shortname = "liu233w";
  var disqus_identifier = "https://liu233w.github.io/2019/05/09/java8-stream-parallel-short-task/";
  var disqus_url = "https://liu233w.github.io/2019/05/09/java8-stream-parallel-short-task/";

  isAgent(getDisqus)

  // determine user agent in China
  function isAgent(cb) {
    var url = '//graph.facebook.com/feed?callback=h';
    var xhr = new XMLHttpRequest();
    var called = false;
    xhr.open('GET', url);
    xhr.onreadystatechange = function () {
      if (xhr.readyState === 4 && xhr.status === 200) {
        called = true;
        cb(true);
      }
    };
    xhr.send();
    // timeout 1s, this facebook API is very fast.
    setTimeout(function () {
      if (!called) {
        xhr.abort();
        cb(false)
      }
    }, 1000);
  }

  function getDisqus(isAgent) {
    var dsq = document.createElement('script');
    dsq.type = 'text/javascript';
    dsq.async = true
    dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
    (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq)
  }
</script>
<!-- disqus 公共JS代码 end -->


<script type="text/javascript">
  (function (d, s) {
    var j, e = d.getElementsByTagName(s)[0];

    if (typeof LivereTower === 'function') {
      return;
    }

    j = d.createElement(s);
    j.src = 'https://cdn-city.livere.com/js/embed.dist.js';
    j.async = true;

    e.parentNode.insertBefore(j, e);
  })(document, 'script');
</script>


  <footer>
  <div class="copyright">
    <div>
      &copy; 2019 | Powered by <a href="https://hexo.io" target="_blank">Hexo</a>&nbsp
    </div>
    <div>
      Theme by <a href="https://github.com/lewis-geek/hexo-theme-Aath" target="_blank">Aath</a>
    </div>
  </div>
</footer>


<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<script src="/lib/in-view.min.js"></script>
<script src="/lib/lodash.min.js"></script>
<script>
  var isDown = true
  var oldY = 0
  inView.offset(50)

  document.body.addEventListener('touchstart', function(){});
  
  window.addEventListener('scroll', _.throttle(e => {
    var currentY = window.scrollY
    if((oldY - currentY) < 0) {
      isDown = true
    } else {
      isDown = false
    }
    oldY = currentY
  }, 250))

  $("article img").each(function() {
      var strA = "<a data-fancybox='gallery' href='" + this.src + "'></a>";
      $(this).wrapAll(strA);
  });

  $('.toc-link').each(function() {
      var href = $(this).attr("href");
      
      inView(href).on('exit', () => {
        if (isDown) {
          handleActive(href)
        }
      })

      inView(href).on('enter', () => {
        if (!isDown) {
          handleActive(href)
        }
      })

      this.onclick = function(e) {
        var pos = $(href).offset().top - 10;
        $("html,body").animate({scrollTop: pos}, 300);
        setTimeout(() => {
          handleActive(href)
        }, 350)
        return false
      }
  })

  function handleActive(href) {
    document.querySelectorAll('.toc-link').forEach(elm => {
      elm.classList.remove('active')
    })
    document.querySelector(".toc [href='"+ href +"']").classList.add('active')
  }
</script>
<script src="/lib/jquery.fancybox.min.js"></script>

<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

</body>
</html>
